package com.imooc.consumer.consumer_mode;

import com.utils.Const;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/4/10-2024
 * @Description: 生产者生产消息
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        //定义生产者
        DefaultMQProducer producer = new DefaultMQProducer("test_consumer_mode");
        producer.setNamesrvAddr(Const.NAME_SERVER_SINGLE);

        //启动生产者
        producer.start();

        //循环发送消息
        for (int i = 0; i < 10; i++) {
            Message message = new Message("test_consumer_mode1_topic", "tags_" + i, "key_" + i, ("第" + i + "条消息 message!!!").getBytes());
            SendResult result = producer.send(message);
            System.out.println(result);
        }

        //关闭生产者
        producer.shutdown();
    }
}